package com.jule.teenpatti.mail.model;

import com.jule.core.common.log.LoggerUtils;
import com.jule.core.jedis.StoredObj;
import com.jule.core.utils.TimeUtil;
import com.jule.teenpatti.mail.dao.bean.MailUserModel;
import lombok.Data;


import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Data
public class UserMailMap extends StoredObj {
    /**
     * <mailConfigId,mailUserModel>
     */
    private Map<Integer, MailUserModel> mailMap = new ConcurrentHashMap<>();

    public boolean isContainsKey(int mailConfigId) {
        return mailMap.containsKey(mailConfigId);
    }

    public void add(List<MailUserModel> list) {
        Iterator<MailUserModel> iter = list.iterator();
        while (iter.hasNext()) {
            MailUserModel model = iter.next();
            long beginTime = TimeUtil.getDateToMillis(model.getCreateTime());
            if (System.currentTimeMillis() >= beginTime) {
                LoggerUtils.mailLog.info("add() mailUserModel：{}", model.toString());
                mailMap.put(model.getMailConfigId(), model);
            }
        }
    }

    public void put(MailUserModel model) {
        long beginTime = TimeUtil.getDateToMillis(model.getCreateTime());
        if (System.currentTimeMillis() >= beginTime) {
            mailMap.put(model.getMailConfigId(), model);
        }
    }
    public void del(int mailConfigId){
        mailMap.remove(mailConfigId);
    }

}
